//
//  InterstitialVideoViewController.m
//  DiscountCoupon
//
//  Created by hongdong.yu on 2018/12/10.
//  Copyright © 2018年 上海宏鹿信息技术服务有限公司. All rights reserved.
//

#import "InterstitialVideoViewController.h"
#import <MTGSDK/MTGSDK.h>
#import <MTGSDKInterstitialVideo/MTGInterstitialVideoAdManager.h>
#import <MTGSDKReward/MTGRewardAdManager.h>
#import <Masonry/Masonry.h>


@interface InterstitialVideoViewController ()<MTGInterstitialVideoDelegate,MTGRewardAdLoadDelegate,MTGRewardAdShowDelegate>

@property (nonatomic,strong) MTGInterstitialVideoAdManager *ivAdManager;

@end

@implementation InterstitialVideoViewController

#pragma mark - ♻️life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

#pragma mark - 🔄overwrite

#pragma mark - 🚪public

#pragma mark - 🍐delegate

#pragma mark - Interstitial Delegate Methods

- (void)onInterstitialVideoLoadSuccess:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
    [self.ivAdManager showFromViewController:self];
}

- (void)onInterstitialVideoLoadFail:(nonnull NSError *)error adManager:(MTGInterstitialVideoAdManager *_Nonnull)adManager;{
}

- (void)onInterstitialVideoShowFail:(nonnull NSError *)error adManager:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
}

- (void)onInterstitialVideoAdClick:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
}

- (void)onInterstitialVideoAdDismissedWithConverted:(BOOL)converted adManager:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
}


#pragma mark - MTGRewardAdLoadDelegate/MTGRewardAdShowDelegate

- (void)onVideoAdLoadSuccess:(nullable NSString *)unitId{
    
    [[MTGRewardAdManager sharedInstance] showVideo:@"65629" withRewardId:@"1" userId:@"" delegate:self viewController:self];
}

- (void)onVideoAdLoadFailed:(nullable NSString *)unitId error:(nonnull NSError *)error{
    
}

- (void)onVideoAdClicked:(nullable NSString *)unitId{
   
}


#pragma mark - ☎️notification

#pragma mark - 🎬event response
-(void)button1Click{
    // 加载视频广告
    [self.ivAdManager loadAd];
}

-(void)button2Click{
    // 加载激励视频广告
    [[MTGRewardAdManager sharedInstance] loadVideo:@"65629" delegate:self];
}






#pragma mark - 🔒private

#pragma mark - 🌲setupUI
-(void)setupUI{

    self.view.backgroundColor = [UIColor whiteColor];
    
    
    self.title = @"赚钱";
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button1 setTitle:@"视频\n线路一" forState:UIControlStateNormal];
    button1.titleLabel.numberOfLines = 0;
    [button1 setBackgroundColor:[UIColor redColor]];
    button1.titleLabel.textAlignment = NSTextAlignmentCenter;
    [button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button1.titleLabel.font = [UIFont systemFontOfSize:18];
    [button1 addTarget:self action:@selector(button1Click) forControlEvents:UIControlEventTouchUpInside];
    button1.layer.cornerRadius = 50;
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button2 setTitle:@"视频\n线路二" forState:UIControlStateNormal];
    button2.titleLabel.numberOfLines = 0;
    [button2 setBackgroundColor:[UIColor redColor]];
    button2.titleLabel.textAlignment = NSTextAlignmentCenter;
    [button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont systemFontOfSize:18];
    [button2 addTarget:self action:@selector(button2Click) forControlEvents:UIControlEventTouchUpInside];
    button2.layer.cornerRadius = 50;



    
    [self.view addSubview:button1];
    [self.view addSubview:button2];
    


    
    CGFloat space = ([UIScreen mainScreen].bounds.size.width - 200) / 3;
    
    [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(space);
        make.top.equalTo(self.view).offset(150);
        make.width.height.mas_equalTo(100);
    }];
    
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-space);
        make.centerY.equalTo(button1);
        make.width.height.mas_equalTo(100);
    }];
    
}

#pragma mark - ☸getter and setter

-(MTGInterstitialVideoAdManager *)ivAdManager{
    if (_ivAdManager == nil) {
        _ivAdManager = [[MTGInterstitialVideoAdManager alloc]initWithUnitID:@"65630" delegate:self];
        _ivAdManager.delegate = self;
    }
    return _ivAdManager;
}





@end
